//获取当前网址，如： http://localhost:8083/myproj/view/my.jsp
var curWwwPath=window.document.location.href;

//获取主机地址之后的目录，如： myproj/view/my.jsp
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);

//获取主机地址，如： http://localhost:8083
var localhostPaht=curWwwPath.substring(0,pos);

//获取带"/"的项目名，如：/myproj
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);

//得到了 http://localhost:8083/myproj
var realPath=localhostPaht+projectName;

//阻止安卓长按事件,禁止右键菜单
// var strUrl=location.href;
// var arrUrl=strUrl.split("/");
// var strPage=arrUrl[arrUrl.length-1];
// if(strPage != 'wechatLogin.html'){
//     document.oncontextmenu=function(e){
//         e.preventDefault();
//     };
// }
// 阻止安卓实体键后退
history.pushState(null,null,location.href);
window.addEventListener('popstate', function(event) {
    //关闭微信浏览器
    WeixinJSBridge.call('closeWindow');
});
//设置AJAX全局默认设置
/*$.ajaxSetup({
        contentType:"application/x-www-form-urlencoded;charset=utf-8",
        complete:function(XMLHttpRequest,textStatus){
            var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); // 通过XMLHttpRequest取得响应头，sessionstatus，
            if(sessionstatus=="timeout"){
                // 如果session过期就重新登录
                alert("页面过期，请重新登录");
                window.top.location.href="/wechaTest.html";
            }
            if(sessionstatus=="repeatlogin"){
                alert("您的帐号已在其他机器登录，请重新登录");
                window.top.location.href="/wechaTest.html";
            }
        }
    }
);*/

//获取屏幕高度
$(document).ready(function(){
    var wh = document.documentElement.clientHeight;
    console.log(wh)
    var html = document.getElementsByTagName("html");

    $(html).height(wh);

})

//登录页
$(".form-radio").click(function(){
	var D_status = $(this).children("i").attr("data-status");
        if(D_status == 0){
            $(this).children("i").removeClass("radiuIconN").addClass("radiuIconY").attr("data-status","1");
        }else{
        	$(this).children("i").removeClass("radiuIconY").addClass("radiuIconN").attr("data-status","0");
        }
    });

//首页
	$(document).ready(function(){
		showTime();
	});
	/*获取日期*/
	function showTime(){
	    var time=new Date();
	    var year=time.getFullYear();
	    var month=time.getMonth();
	    var date=time.getDate();
	    var day=time.getDay();
	    var hour=time.getHours();
	    var minutes=time.getMinutes();
	    var second=time.getSeconds();
	    month = parseInt(month)+ 1;
	    month<10?month='0'+month:month;
	    date<10?date='0'+date:date;
	    hour<10?hour='0'+hour:hour;
	    minutes<10?minutes='0'+minutes:minutes;
	    second<10?second='0'+second:second;
	    var nyr = year+'-'+month+'-'+date;
	    var hms = hour+':'+minutes;
	    $(".date").html(nyr);
	    $(".day").html(hms);
	    setTimeout("showTime()",1000);
	};
//历史轨迹
$(".ShowPosition").click(function(){
        var D_status = $(this).children("i").attr("data-status");
        if(D_status == 0){
            $(this).children("i").removeClass("TabIconN").addClass("TabIconY").attr("data-status","1");
        }else{
        	$(this).children("i").removeClass("TabIconY").addClass("TabIconN").attr("data-status","0");
        }
    });
$(document).ready(function(){
    	// var WH_HR = window.screen.height;
        // var buttonH = $(".HRbutton").height();
        // var HRcontent = $(".HR-content").height();
    	// $(".HRbutton").css("margin-top",WH_HR - HRcontent - buttonH/3);

    $(".HR-tab").on("click","div",function(){
    	        var _this=this;
				$(this).children("i").removeClass("TabIconN").addClass("TabIconY");
				$(this).siblings().children("i").removeClass("TabIconY").addClass("TabIconN");
				//获取当前data-day
				var whichday = $(this).children("span").attr("data-day");
				if(whichday == 'J'){

                    $('#start_date').attr("disabled",true);
                    $('#end_date').attr("disabled",true);
                    $('#start_time').attr("disabled",true);
                    $('#end_time').attr("disabled",true);
                    todayTime();
                    $("#text_tip").hide();
				}else if(whichday == 'Z'){

                    $('#start_date').attr("disabled",true);
                    $('#end_date').attr("disabled",true);
                    $('#start_time').attr("disabled",true);
                    $('#end_time').attr("disabled",true);
                    lastdaytime();
                    $("#text_tip").hide();
				}else if(whichday == 'S'){
                    $('#start_date').attr("disabled",false);
                    $('#end_date').attr("disabled",false);
                    $('#start_time').attr("disabled",false);
                    $('#end_time').attr("disabled",false);
					blanktime();
					$("#text_tip").show();
				}else{
                    layerMsg("出错啦！",2)
				}
		})
        var startTime = $(".HrTab-time .timeLocation #start_time");
        var nowtime = $(".HrTab-time .timeLocation #end_time");
		var nowdate = $(".HrTab-time .dateLocation input");

		function todayTime(){
            var time=new Date();
            var year=time.getFullYear();
            var month=time.getMonth();
            var date=time.getDate();
            var day=time.getDay();
            var hour=time.getHours();
            var minutes=time.getMinutes();
            var second=time.getSeconds();
            month = parseInt(month)+ 1;
            month<10?month='0'+month:month;
            date<10?date='0'+date:date;
            hour<10?hour='0'+hour:hour;
            minutes<10?minutes='0'+minutes:minutes;
            second<10?second='0'+second:second;
            var nyr = year+'-'+month+'-'+date;
            var hms = hour+':'+minutes+':'+second;
            $(startTime).val("00:00:00");
	    $(nowdate).val(nyr);
	    $(nowtime).val(hms);
	};
	todayTime();
	function lastdaytime(){
		var day1 = new Date();
		day1.setDate(day1.getDate() - 1);
		var s1 = day1.format("yyyy-MM-dd");
		$(nowdate).val(s1);
        $(nowtime).val('23:59:59');
	}
	function blanktime(){
        var time=new Date();
        var year=time.getFullYear();
        var month=time.getMonth();
        var date=time.getDate();
        var day=time.getDay();
        var hour=time.getHours();
        var minutes=time.getMinutes();
        var second=time.getSeconds();
        month = parseInt(month)+ 1;
        month<10?month='0'+month:month;
        date<10?date='0'+date:date;
        hour<10?hour='0'+hour:hour;
        minutes<10?minutes='0'+minutes:minutes;
        second<10?second='0'+second:second;
        var nyr = year+'-'+month+'-'+date;
        var hms = hour+':'+minutes+':'+second;
        $(startTime).val("00:00:00");
		$(nowdate).val(nyr);
		$(nowtime).val(hms);
	}
})
//设置
	//设置定时时间间隔
	 var settingModle;
	//短信告警电话
	var  msgPhonenum="";
	//第一紧急电话
	var firstCallPhonenum="";
	//第二紧急电话
	var secondCallPhonenum="";
	//设备到期日期
	var terminalCutoffDate;

$(document).ready(function(){
	$(".mui-table-view").on("click",".Hmsk",function(){
		var name = $(this).attr("data-which");
		console.log(name)
		$(this).parents(".setting").siblings(".popupWindow").removeClass("close").addClass("open");
		$(this).parents(".setting").siblings(".mask").removeClass("close").addClass("open");
		
		$(".Wcontent").html('');
		$(".buttonWrap").html('');
		var html = '';
		var btnHtml = '';

		var   class1 = 'TabIconN'
			, class3 = 'TabIconN';

		if(settingModle) {//第一次进入没有内容不判断，判断不等于空

            settingModle = $.trim(settingModle);

			if(settingModle == '0'){

				class1 = 'TabIconY';

			}else{

                settingModle = $('#settingModle').find("i").html();

                settingModle = $.trim(settingModle);

                if(settingModle=='2'){

                    class3 = 'TabIconY';

                }
			}


		}else{
            class1 = 'TabIconY';
        }

		
	switch(name){
	    case 'WorkMode':
	    		html = "<div id='workModle' class='mode'>" +
	    					"<h3>工作模式</h3>" +
	    					"<div class='p_wrap'>" +
	    						"<p class='flexp'>" +
		    						"<span data-name='1'>精准模式（10秒钟一次定位）<i style='display:none;'>0</i></span>" +
		    						"<span><i class='status "+ class1+"' data-status=''></i></span>" +
	    						"</p>" +
	    						"<p class='flexp'>" +
		    						"<span data-name='3'>标准模式（5分钟一次定位）<i style='display:none;'>2</i></span>" +
		    						"<span><i class='status "+class3+"' data-status=''></i></span>" +
	    						"</p>" +
	    						"</div>" +
    						"</div>";
	    		
	        btnHtml="<div class='cancle'><button >取消</button></div><div><button class='sure' onclick='updateModel();'>确认</button></div>";
	        break;
	    case 'monitoring':
	    	
	        html = "<div  class='moniNUM'><h3>短信监控号码</h3><p><input id='sms' type='text' placeholder='监控号码' value='"+msgPhonenum+"'/></p></div>";
	        btnHtml="<div class='cancle'><button >取消</button></div><div><button class='sure' onclick='updateMsgPhonenum();'>确认</button></div>";
	        break;
	    case 'urgencyhelp':
	    	html = "<div class='helpcall'><h3>紧急呼叫</h3><p><input id='firstCallPhonenum' type='text' placeholder='紧急号码1'  value='"+firstCallPhonenum+"'/><input id='secondCallPhonenum' type='text' placeholder='紧急号码2' value='"+secondCallPhonenum+"'/></p></div>";
	    	btnHtml="<div class='cancle'><button >取消</button></div><div><button class='sure' onclick='updatehelpcall();'>确认</button></div>";
	  	    break;
	    case 'revisepassword' :
	    	reviseAndquipInfo(repassword)
	    	break;
	    case 'quipInfo' :
	    	reviseAndquipInfo(quipment)
	    	break;
	}   
	$(".Wcontent").append(html);
	$(".buttonWrap").append(btnHtml);

        var i_html = $(".flexp").find(".status");
        for(s = 0;s < i_html.length;s++){
           var _thisS = $(i_html[s]);

            if(_thisS.hasClass("TabIconY")){
                _thisS.attr("data-status","1");
			}else{
                _thisS.attr("data-status","0")
			}
		}

	});
	
	//点击取消关闭弹窗
	$(".buttonWrap").on('click','.cancle',function(){
		
		var parentName = $(this).parents(".popupWindow");
		$(parentName).siblings(".mask").removeClass("open").addClass("close");
		$(parentName).removeClass("open").addClass("close");
		
	});
	//点击确定关闭弹窗
	$(".buttonWrap").on('click',' .sure',function(){
		var parentName = $(this).parents(".popupWindow");
		$(parentName).siblings(".mask").removeClass("open").addClass("close");
		$(parentName).removeClass("open").addClass("close");
		
	})

	
	
		$(".mui-table-view").on("click",".hrefpage",function(){
			var Name = $(this).attr("data-which");
			switch(Name){
			    case 'revisepassword' :
			    window.location.href = 'revise_quip.html?name='+ Name;
			    	break;
			    case 'quipInfo' :
			    window.location.href = 'revise_quip.html?name='+ Name;
			    	break;
			}    
		});
		var url = location.search;
		var now_page = url.split("=")[1];
		reviseAndquipInfo(now_page);
		function reviseAndquipInfo(Wpage){
			//判断是哪个页面
			var pageHtml = '';

			$(".reviseContent").html('');

			if(Wpage == 'revisepassword'){
				pageHtml = "<ul><li><lable>原密码：</lable><input type='password' placeholder='输入原密码' id='oldPwd'/></li><li><lable>新密码：</lable><input type='password' placeholder='输入新密码' id='newPwd'/></li><li><lable>重复新密码：</lable><input type='password' placeholder='再次输入新密码' id='confirmPwd'/></li><div class='HRbuttonWrap'><button id='terminalSave' class='RVbutton' onclick='updatePwd()' id='modifyPwd'>保存</button></div></ul>"

			}else if(Wpage == 'quipInfo'){
				pageHtml = "<form id='terInfoId' action='termianlinfo/updateTerminalInfo' method='post'><ul>" +
				"<li><lable>登录名：</lable><input id= 'tName' name='terminalName' type='text' placeholder='输入登录名' required='required' /></li>" +
				"<li class='disabled'><lable>设备编号：</lable><input id='tNumber'  name ='terminalNumber' type='text' placeholder='' required='required'  disabled='true' /></li>" +
				"<li class='disabled'><lable>到期时间：</lable><input id='tCutoffDate' name ='terminalCutOffDateStr' type='text' placeholder=''  disabled='true' /></li>" +
				"<li class='disabled'><lable>设备型号：</lable><input id= 'tType' name ='terminalType' type='text' placeholder='' required='required' disabled='true'  /></li>" +
				"<li><lable>设备昵称：</lable><input id= 'tNickName' name ='terminalNickname'type='text' placeholder='输入设备昵称' required='required'/></li>" +
				"<li><lable>设备电话：</lable><input id= 'tPhone' name ='terminalPhone'type='text' placeholder='输入设备电话' required='required'/></li>" +
				"<li><lable>联系人：</lable><input id= 'tLinkTerinal' name ='linkTerminal'type='text' placeholder='输入联系人' required='required'" +
				"/></li>" +
				"<li><lable>联系电话：</lable><input id= 'tLinkTerminalPhone' name ='linkTerminalPhone'type='text' placeholder='请输入联系电话' required='required'/></li>" +
				"</ul><div class='HRbuttonWrap'><button class='HRbutton' id='saveTerminalInfo'>保存</button></div></form>"

			}
			//
			$(".reviseContent").append(pageHtml);
			// $(".HRbuttonWrap").append(btnHtml);
			save();
		}
		function save(){
			var WH_re = window.screen.height;
			var RVbutton = $(".RVbutton").height();
            var rv = RVbutton/2 + RVbutton;
			var reviseContent = $(".reviseContent").height();
	    	$(".RVbutton").css("margin-top",WH_re - reviseContent - rv);
		}
		
		
//电子围栏见页AreaEdit.html
/*
//设备信息
	rolerHtml = '';
	$(".switch").click(function(){
		var D_ROLER = $(this).parent().siblings().children("ul").attr("data-roler");

		if(D_ROLER == 'sendInfo'){
			$(this).parent().siblings().children("ul").attr("data-roler","feedback");
			$(".EquipInfoContent ul").html('');
			rolerHtml = "<li><p><span class='cast'>远程关机</span><span class='sendTime'><lable>发送时间：</lable><a class='Sdate MLcss'>2018-2-2</a><a class='Stime'>00:00:00</a></span></p><p><span class='success'>发送成功</span><span class='replyTime'><lable>回复时间：</lable><a class='Rdate MLcss'>2018-2-2</a><a class='Rtime'>00:00:00</a></span></p></li><li><p><span class='cast'>远程关机</span><span class='sendTime'><lable>发送时间：</lable><a class='Sdate MLcss'>2018-2-2</a><a class='Stime'>00:00:00</a></span></p><p><span class='fail'>发送失败</span><span class='replyTime'><lable>回复时间：</lable><a class='Sdate MLcss'>2018-2-2</a><a class='Stime'>00:00:00</a></span></p></li>"
		}else if(D_ROLER == 'feedback'){
			$(this).parent().siblings().children("ul").attr("data-roler","sendInfo");
			$(".EquipInfoContent ul").html('');
			rolerHtml = "<li><p><span class='cast'>远程关机111111</span><span class='sendTime'><lable>发送时间：</lable><a class='Sdate MLcss'>2018-2-2</a><a class='Stime'>00:00:00</a></span></p><p><span class='success'>发送成功</span><span class='replyTime'><lable>回复时间：</lable><a class='Rdate MLcss'>2018-2-2</a><a class='Rtime'>00:00:00</a></span></p></li><li><p><span class='cast'>远程关机</span><span class='sendTime'><lable>发送时间：</lable><a class='Sdate MLcss'>2018-2-2</a><a class='Stime'>00:00:00</a></span></p><p><span class='fail'>发送失败</span><span class='replyTime'><lable>回复时间：</lable><a class='Sdate MLcss'>2018-2-2</a><a class='Stime'>00:00:00</a></span></p></li>"
		}
		$(".EquipInfoContent ul").append(rolerHtml);
	})
	$(".refurbish").click(function(){
		 location.reload();
	})*/

	
});

//封装layer的信息提示框
function layerMsg(msg,time){
    layer.open({
        anim: 'up'
        ,content: msg
        ,skin: 'msg'
        ,time: time //自动关闭时间（秒）
    });
}
// 自定义手动关闭提示框
function laSelfMsg(msg){
    layer.open({
        anim: 'up'
        ,content: msg
        , btn: ['确定']
        , yes: function (index, layero) {
            window.top.location.href="/wechatLogin.html";
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
        ,skin: 'laySelfClass'
    })
}

